package com.vogue.supplymall.admin.business;

import com.vogue.configs.startup.SpringContext;
import com.vogue.configs.startup.SpringStart;
import com.vogue.gear.memory.provider.annotation.MemorySchemeP2P;
import com.vogue.ssm.controller.help.ErrorMsg;
import com.vogue.ssm.database.annotation.ScanEntity;
import com.vogue.ssm.database.entity.SnowflakeIdWorker;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.MultipartAutoConfiguration;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Import;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.HashMap;
import java.util.Map;

/**
 * @aouthor: zhangliang
 * @date: Create in 2018-04-24
 */
@SpringBootApplication(exclude = {MultipartAutoConfiguration.class})
@EnableTransactionManagement
@EnableAsync
@MemorySchemeP2P
@ScanEntity(scanPack = { "com.vogue.supplymall.account.domain.model"})
@Import({SpringContext.class})
@EnableScheduling
public class AdminBusinessApplication {

    public static void main(String[] args) {
        Map<String, String> mapargs = transargs(args);
        if (mapargs.size() > 0) {
            //所在服务器编号
            String s1 = mapargs.get("serno");
            if (StringUtils.isNotEmpty(s1)) {
                SnowflakeIdWorker.serno = Integer.parseInt(s1);
            }
            //同一服务器中服务的编号
            s1 = mapargs.get("dsno");
            if (StringUtils.isNotEmpty(s1)) {
                SnowflakeIdWorker.dsno = Integer.parseInt(s1);
            }
        }
        SpringStart.run(AdminBusinessApplication.class, args);
        ErrorMsg.deftemp="%s";
    }

    private static Map<String, String> transargs(String[] args) {
        Map<String, String> mapargs = new HashMap();
        if (args != null) {
            for (String arg : args) {
                if (arg.startsWith("--")) {
                    int pos = arg.indexOf("=");
                    if (pos > 0) {
                        mapargs.put(arg.substring(2, pos), arg.substring(pos + 1));
                    }
                }
            }
        }
        return mapargs;
    }
}
